//
//  GuangGuangViewController.m
//  Wedding fantastic
//
//  Created by dllo on 15/7/6.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "GuangGuangViewController.h"

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@interface GuangGuangViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate>
// 婚纱
@property (nonatomic, retain) UICollectionView *hunShaCollection;
// 礼服
@property (nonatomic, retain) UICollectionView *liFuCollection;
// 婚鞋
@property (nonatomic, retain) UICollectionView *hunXieCollection;
// 配饰
@property (nonatomic, retain) UICollectionView *peiShiCollection;
// 首饰
@property (nonatomic, retain) UICollectionView *shouShiCollection;
// 婚庆用品
@property (nonatomic, retain) UICollectionView *hunQingCollection;
// 家具用品
@property (nonatomic, retain) UICollectionView *jiaJuCollection;
// 底部scrollview
@property (nonatomic, retain) UIScrollView *backScrollView;

@property (nonatomic, retain) CCSegmentedControl *listSegmented;

// 接收婚纱数据的数组
@property (nonatomic, retain) NSMutableArray *dataArr;
// 接收礼服数据的数组
@property (nonatomic, retain) NSMutableArray *liFuArr;
// 接收婚鞋数据的数组
@property (nonatomic, retain) NSMutableArray *hunXieArr;
// 接收配饰数据的数组
@property (nonatomic, retain) NSMutableArray *peiShiArr;
// 接收首饰数据的数组
@property (nonatomic, retain) NSMutableArray *shouShiArr;
// 接收婚庆用品数据的数组
@property (nonatomic, retain) NSMutableArray *hunQingArr;
// 接收家居用品数据的数组
@property (nonatomic, retain) NSMutableArray *jiaJuArr;

@property (nonatomic, retain) MBProgressHUD *HUD;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, assign) BOOL loading;

@end

@implementation GuangGuangViewController

- (void)dealloc
{
    [_hunShaCollection release];
    [_dataArr release];
    [_HUD release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:241 / 255.0 green:241 / 255.0 blue:240 / 255.0 alpha:1];
    self.navigationItem.title = @"看看";
    // 设置标题颜色
    self.navigationController.navigationBar.tintColor = [UIColor brownColor];
    // 字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor brownColor],NSForegroundColorAttributeName,nil]];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png" ] style:UIBarButtonItemStyleDone target:self action:@selector(leftBack:)];
    
    //
    self.backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30 * HEIGHT / 667, WIDTH, HEIGHT)];
    [self.view addSubview:self.backScrollView];
    self.backScrollView.pagingEnabled = NO;
    self.backScrollView.delegate = self;
    // 设置滚动范围
    self.backScrollView.contentSize = CGSizeMake(WIDTH * 7, 0);
    [_backScrollView release];
    self.backScrollView.pagingEnabled = YES;
    // 不显示滚动条
    //    self.backScrollView.showsVerticalScrollIndicator = FALSE;
    
    // 放segmented的
    UIScrollView *segScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 50 * HEIGHT / 667)];
    [self.view addSubview:segScroll];
    segScroll.contentSize = CGSizeMake(WIDTH * 1.35, 0);
    segScroll.pagingEnabled = NO;
    // 隐藏滚动条
    segScroll.showsHorizontalScrollIndicator = FALSE;
    [segScroll release];
    
    //segmented
    self.listSegmented = [[CCSegmentedControl alloc] initWithItems:@[@"婚纱", @"礼服", @"婚鞋", @"配饰",@"首饰",@"婚庆用品",@"家居礼品"]];
    self.listSegmented.frame = CGRectMake(0, 0, 500 * WIDTH / 375, 50 * HEIGHT / 667);
    self.listSegmented.layer.borderWidth = 0.5;
    self.listSegmented.layer.borderColor = [[UIColor brownColor] CGColor];
    //设置背景图片，或者设置颜色，或者使用默认白色外观
//    listSegmented.backgroundImage = [UIImage imageNamed:@"segment_bg.png"];
    self.listSegmented.backgroundColor = [UIColor whiteColor];
    
    //阴影部分图片，不设置使用默认椭圆外观的stain
//    listSegmented.selectedStainView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"stain.png"]];
    self.listSegmented.selectedStainView = [[UIImageView alloc] init];
    self.listSegmented.selectedSegmentTextColor = [UIColor brownColor];
    self.listSegmented.segmentTextColor = [self colorWithHexString:@"#535353"];
    [self.listSegmented addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    [segScroll addSubview:self.listSegmented];
    
    
    // 婚纱
    // 苹果官方提供的一种瀑布流效果
    UICollectionViewFlowLayout *hunShaFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 每一个item的大小
    hunShaFlowLayout.itemSize = CGSizeMake(150 * WIDTH / 375, 160 * HEIGHT / 667);
    hunShaFlowLayout.sectionInset = UIEdgeInsetsMake(5 * WIDTH / 375, 25 * HEIGHT / 667, 5 * WIDTH / 375, 25 * HEIGHT / 667);
    hunShaFlowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    self.hunShaCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 20 * HEIGHT / 667, WIDTH, 510 * HEIGHT / 667) collectionViewLayout:hunShaFlowLayout];
    self.hunShaCollection.backgroundColor = [UIColor whiteColor];
    // collectionView和tableView很相似,使用前需要先签订两个协议,一个dataSource,一个delegate
    self.hunShaCollection.delegate = self;
    self.hunShaCollection.dataSource = self;
    [self.backScrollView addSubview:self.hunShaCollection];
    [_hunShaCollection release];
    // 注册
    // 第一个参数:需要指定注册类型
    // 第二个参数:重用的标志
    [self.hunShaCollection registerClass:[GoodsCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];

    
    // 礼服
    // 苹果官方提供的一种瀑布流效果
    UICollectionViewFlowLayout *liFuFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 每一个item的大小
    liFuFlowLayout.itemSize = CGSizeMake(150 * WIDTH / 375, 160 * HEIGHT / 667);
    liFuFlowLayout.sectionInset = UIEdgeInsetsMake(5 * WIDTH / 375, 25 * HEIGHT / 667, 5 * WIDTH / 375, 25 * HEIGHT / 667);
    
    self.liFuCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH, 20 * HEIGHT / 667, WIDTH, 510 * HEIGHT / 667) collectionViewLayout:liFuFlowLayout];
    self.liFuCollection.backgroundColor = [UIColor whiteColor];
    // collectionView和tableView很相似,使用前需要先签订两个协议,一个dataSource,一个delegate
    self.liFuCollection.delegate = self;
    self.liFuCollection.dataSource = self;
    [self.backScrollView addSubview:self.liFuCollection];
    [_liFuCollection release];
    // 注册
    // 第一个参数:需要指定注册类型
    // 第二个参数:重用的标志
    [self.liFuCollection registerClass:[GoodsCollectionViewCell class] forCellWithReuseIdentifier:@"liFuReuse"];
    
    // 婚鞋
    // 苹果官方提供的一种瀑布流效果
    UICollectionViewFlowLayout *hunXieFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 每一个item的大小
    hunXieFlowLayout.itemSize = CGSizeMake(150 * WIDTH / 375, 160 * HEIGHT / 667);
    hunXieFlowLayout.sectionInset = UIEdgeInsetsMake(5 * WIDTH / 375, 25 * HEIGHT / 667, 5 * WIDTH / 375, 25 * HEIGHT / 667);
    
    self.hunXieCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH * 2, 20 * HEIGHT / 667, WIDTH, 510 * HEIGHT / 667) collectionViewLayout:hunXieFlowLayout];
    self.hunXieCollection.backgroundColor = [UIColor whiteColor];
    // collectionView和tableView很相似,使用前需要先签订两个协议,一个dataSource,一个delegate
    self.hunXieCollection.delegate = self;
    self.hunXieCollection.dataSource = self;
    [self.backScrollView addSubview:self.hunXieCollection];
    [_hunXieCollection release];
    // 注册
    // 第一个参数:需要指定注册类型
    // 第二个参数:重用的标志
    [self.hunXieCollection registerClass:[GoodsCollectionViewCell class] forCellWithReuseIdentifier:@"hunXieReuse"];
    
    // 配饰
    // 苹果官方提供的一种瀑布流效果
    UICollectionViewFlowLayout *peiShiFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 每一个item的大小
    peiShiFlowLayout.itemSize = CGSizeMake(150 * WIDTH / 375, 160 * HEIGHT / 667);
    peiShiFlowLayout.sectionInset = UIEdgeInsetsMake(5 * WIDTH / 375, 25 * HEIGHT / 667, 5 * WIDTH / 375, 25 * HEIGHT / 667);
    
    self.peiShiCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH * 3, 20 * HEIGHT / 667, WIDTH, 510 * HEIGHT / 667) collectionViewLayout:peiShiFlowLayout];
    self.peiShiCollection.backgroundColor = [UIColor whiteColor];
    // collectionView和tableView很相似,使用前需要先签订两个协议,一个dataSource,一个delegate
    self.peiShiCollection.delegate = self;
    self.peiShiCollection.dataSource = self;
    [self.backScrollView addSubview:self.peiShiCollection];
    [_peiShiCollection release];
    // 注册
    // 第一个参数:需要指定注册类型
    // 第二个参数:重用的标志
    [self.peiShiCollection registerClass:[GoodsCollectionViewCell class] forCellWithReuseIdentifier:@"peiShiReuse"];
    
    // 首饰
    // 苹果官方提供的一种瀑布流效果
    UICollectionViewFlowLayout *shouShiFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 每一个item的大小
    shouShiFlowLayout.itemSize = CGSizeMake(150 * WIDTH / 375, 160 * HEIGHT / 667);
    shouShiFlowLayout.sectionInset = UIEdgeInsetsMake(5 * WIDTH / 375, 25 * HEIGHT / 667, 5 * WIDTH / 375, 25 * HEIGHT / 667);
    
    self.shouShiCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH * 4, 20 * HEIGHT / 667, WIDTH, 510 * HEIGHT / 667) collectionViewLayout:shouShiFlowLayout];
    self.shouShiCollection.backgroundColor = [UIColor whiteColor];
    // collectionView和tableView很相似,使用前需要先签订两个协议,一个dataSource,一个delegate
    self.shouShiCollection.delegate = self;
    self.shouShiCollection.dataSource = self;
    [self.backScrollView addSubview:self.shouShiCollection];
    [_shouShiCollection release];
    // 注册
    // 第一个参数:需要指定注册类型
    // 第二个参数:重用的标志
    [self.shouShiCollection registerClass:[GoodsCollectionViewCell class] forCellWithReuseIdentifier:@"shouShiReuse"];
    
    // 婚庆用品
    // 苹果官方提供的一种瀑布流效果
    UICollectionViewFlowLayout *hunQingFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 每一个item的大小
    hunQingFlowLayout.itemSize = CGSizeMake(150 * WIDTH / 375, 160 * HEIGHT / 667);
    hunQingFlowLayout.sectionInset = UIEdgeInsetsMake(5 * WIDTH / 375, 25 * HEIGHT / 667, 5 * WIDTH / 375, 25 * HEIGHT / 667);
    
    self.hunQingCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH * 5, 20 * HEIGHT / 667, WIDTH, 510 * HEIGHT / 667) collectionViewLayout:hunQingFlowLayout];
    self.hunQingCollection.backgroundColor = [UIColor whiteColor];
    // collectionView和tableView很相似,使用前需要先签订两个协议,一个dataSource,一个delegate
    self.hunQingCollection.delegate = self;
    self.hunQingCollection.dataSource = self;
    [self.backScrollView addSubview:self.hunQingCollection];
    [_hunQingCollection release];
    // 注册
    // 第一个参数:需要指定注册类型
    // 第二个参数:重用的标志
    [self.hunQingCollection registerClass:[GoodsCollectionViewCell class] forCellWithReuseIdentifier:@"hunQingReuse"];
    
    // 家居用品
    // 苹果官方提供的一种瀑布流效果
    UICollectionViewFlowLayout *jiaJuFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 每一个item的大小
    jiaJuFlowLayout.itemSize = CGSizeMake(150 * WIDTH / 375, 160 * HEIGHT / 667);
    jiaJuFlowLayout.sectionInset = UIEdgeInsetsMake(5 * WIDTH / 375, 25 * HEIGHT / 667, 5 * WIDTH / 375, 25 * HEIGHT / 667);
    
    self.jiaJuCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH * 6, 20 * HEIGHT / 667, WIDTH, 510 * HEIGHT / 667) collectionViewLayout:jiaJuFlowLayout];
    self.jiaJuCollection.backgroundColor = [UIColor whiteColor];
    // collectionView和tableView很相似,使用前需要先签订两个协议,一个dataSource,一个delegate
    self.jiaJuCollection.delegate = self;
    self.jiaJuCollection.dataSource = self;
    [self.backScrollView addSubview:self.jiaJuCollection];
    [_jiaJuCollection release];
    // 注册
    // 第一个参数:需要指定注册类型
    // 第二个参数:重用的标志
    [self.jiaJuCollection registerClass:[GoodsCollectionViewCell class] forCellWithReuseIdentifier:@"jiaJuReuse"];


    // 回到顶部button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(300 * WIDTH / 375, 450 * HEIGHT / 667, 35 * WIDTH / 375, 35 * HEIGHT / 667);
    [button setBackgroundImage:[UIImage imageNamed:@"backTop"] forState:UIControlStateNormal];
    button.alpha = 0.6;
    [self.view addSubview:button];
    [button addTarget:self action:@selector(backTop:) forControlEvents:UIControlEventTouchUpInside];
    
    self.page = 1;
    [self createData];
    [self createLiFu];
    [self createHunXie];
    [self createPeiShi];
    [self createShouShi];
    [self createHunQing];
    [self createJiaJu];
    [self addHeader];
    [self addFooter];
    
}

// 回到顶部
- (void)backTop:(UIButton *)button
{
    [self.hunShaCollection setContentOffset:CGPointZero animated:YES];
    [self.liFuCollection setContentOffset:CGPointZero animated:YES];
    [self.hunXieCollection setContentOffset:CGPointZero animated:YES];
    [self.peiShiCollection setContentOffset:CGPointZero animated:YES];
    [self.shouShiCollection setContentOffset:CGPointZero animated:YES];
    [self.hunQingCollection setContentOffset:CGPointZero animated:YES];
    [self.jiaJuCollection setContentOffset:CGPointZero animated:YES];
}

- (void)addHeader
{
    __block GuangGuangViewController *guangVC = self;
    
    // 婚纱
    // 添加下拉刷新头部控件
    [self.hunShaCollection addHeaderWithCallback:^{
        // 进入刷新状态就会回调这个Block
        guangVC.loading = NO;//标记为下拉操作
        [self.hunShaCollection reloadData];
        [self.hunShaCollection headerEndRefreshing];
    }];
    
    // 礼服
    // 添加下拉刷新头部控件
    [self.liFuCollection addHeaderWithCallback:^{
        // 进入刷新状态就会回调这个Block
        guangVC.loading = NO;//标记为下拉操作
        [self.liFuCollection reloadData];
        [self.liFuCollection headerEndRefreshing];
    }];

    // 婚鞋
    // 添加刷新头部控件
    [self.hunXieCollection addHeaderWithCallback:^{
        // 进入刷新状态就会回调这个Block
        guangVC.loading = NO;//标记为下拉操作
        [self.hunXieCollection reloadData];
        [self.hunXieCollection headerEndRefreshing];
    }];

    // 配饰
    // 添加刷新头部控件
    [self.peiShiCollection addHeaderWithCallback:^{
        // 进入刷新状态就会回调这个Block
        guangVC.loading = NO;//标记为下拉操作
        [self.peiShiCollection reloadData];
        [self.peiShiCollection headerEndRefreshing];
    }];

    // 首饰
    [self.shouShiCollection addHeaderWithCallback:^{
        guangVC.loading = NO;
        [self.shouShiCollection reloadData];
        [self.shouShiCollection headerEndRefreshing];
    }];
    
    // 婚庆
    [self.hunQingCollection addHeaderWithCallback:^{
        guangVC.loading = NO;
        [self.hunQingCollection reloadData];
        [self.hunQingCollection headerEndRefreshing];
    }];
    
    // 家居
    [self.jiaJuCollection addHeaderWithCallback:^{
        guangVC.loading = NO;
        [self.jiaJuCollection reloadData];
        [self.jiaJuCollection headerEndRefreshing];
    }];
}

- (void)addFooter
{
    __block GuangGuangViewController *guangVC = self;
    
    // 婚纱
    [self.hunShaCollection addFooterWithCallback:^{
        guangVC.loading = NO;
        [self footerRereshing];
    }];

    // 礼服
    [self.liFuCollection addFooterWithCallback:^{
        guangVC.loading = NO;
        [self liFufooterRereshing];
    }];

    // 婚鞋
    // 添加刷新底部控件
    [self.hunXieCollection addFooterWithCallback:^{
        // 进入刷新状态就会回调这个Block
        guangVC.page = 1;
        guangVC.loading = NO;//标记为下拉操作
        [self hunXiefooterRereshing];
    }];

    // 配饰
    [self.peiShiCollection addFooterWithCallback:^{
        // 进入刷新状态就会回调这个Block
        guangVC.page = 1;
        guangVC.loading = NO;//标记为下拉操作
        [self peiShifooterRereshing];
    }];
    
    // 首饰
    [self.shouShiCollection addFooterWithCallback:^{
        guangVC.loading = NO;
        [self shouShifooterRereshing];
    }];
    
    // 婚庆
    [self.hunQingCollection addFooterWithCallback:^{
        guangVC.loading = NO;
        [self hunQingfooterRereshing];
    }];
    
    // 家居
    [self.jiaJuCollection addFooterWithCallback:^{
        guangVC.loading = NO;
        [self jiaJufooterRereshing];
    }];

}

// 上拉
- (void)footerRereshing
{
    self.page++;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://hunliji.com/products.json?page=%ld&user_id=984695&category=1&sort=0", (long)self.page] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.dataArr addObject:model];
            [model release];
        }
        [self.hunShaCollection reloadData];
        [self.hunShaCollection footerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// 礼服
// 上拉
- (void)liFufooterRereshing
{
    self.page++;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://hunliji.com/products.json?page=%ld&user_id=984695&category=2", (long)self.page] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.liFuArr addObject:model];
            [model release];
        }
        [self.liFuCollection reloadData];
        [self.liFuCollection footerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// 婚鞋
// 上拉
- (void)hunXiefooterRereshing
{
    self.page++;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://hunliji.com/products.json?page=%ld&user_id=984695&category=3", (long)self.page] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.hunXieArr addObject:model];
            [model release];
        }
        [self.hunXieCollection reloadData];
        [self.hunXieCollection footerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// 配饰
// 上拉
- (void)peiShifooterRereshing
{
    self.page++;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://hunliji.com/products.json?page=%ld&user_id=984695&category=4", (long)self.page] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.peiShiArr addObject:model];
            [model release];
        }
        [self.peiShiCollection reloadData];
        [self.peiShiCollection footerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// 首饰
// 上拉
- (void)shouShifooterRereshing
{
    self.page++;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://hunliji.com/products.json?page=%ld&user_id=984695&category=5", (long)self.page] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.shouShiArr addObject:model];
            [model release];
        }
        [self.shouShiCollection reloadData];
        [self.shouShiCollection footerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// 婚庆
// 上拉
- (void)hunQingfooterRereshing
{
    self.page++;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://hunliji.com/products.json?page=%ld&user_id=984695&category=6", (long)self.page] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.hunQingArr addObject:model];
            [model release];
        }
        [self.hunQingCollection reloadData];
        [self.hunQingCollection footerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// 家居
// 上拉
- (void)jiaJufooterRereshing
{
    self.page++;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://hunliji.com/products.json?page=%ld&user_id=984695&category=7", (long)self.page] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.jiaJuArr addObject:model];
            [model release];
        }
        [self.jiaJuCollection reloadData];
        [self.jiaJuCollection footerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// collectionView方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if ([collectionView isEqual:self.hunShaCollection]) {
        return self.dataArr.count;
    } else if ([collectionView isEqual:self.liFuCollection]) {
        return self.liFuArr.count;
    } else if ([collectionView isEqual:self.hunXieCollection]) {
        return self.hunXieArr.count;
    } else if ([collectionView isEqual:self.peiShiCollection]) {
        return self.peiShiArr.count;
    } else if ([collectionView isEqual:self.shouShiCollection]) {
        return self.shouShiArr.count;
    } else if ([collectionView isEqual:self.hunQingCollection]) {
        return self.hunQingArr.count;
    } else {
        return self.jiaJuArr.count;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.hunShaCollection]) {
        GoodsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
        RecommendModel *model = self.dataArr[indexPath.row];
        cell.backgroundColor = [UIColor whiteColor];
        [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model.photo_path]];
        cell.priceLabel.text = [NSString stringWithFormat:@"￥%@", [model.price stringValue]];
        cell.recommendLabel.text = [model.like_count stringValue];
        return cell;
    } else if ([collectionView isEqual:self.liFuCollection]) {
        GoodsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"liFuReuse" forIndexPath:indexPath];
        RecommendModel *model = self.liFuArr[indexPath.row];
        cell.backgroundColor = [UIColor whiteColor];
        [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model.photo_path]];
        cell.priceLabel.text = [NSString stringWithFormat:@"￥%@", [model.price stringValue]];
        cell.recommendLabel.text = [model.like_count stringValue];
        return cell;
    } else if ([collectionView isEqual:self.hunXieCollection]) {
        GoodsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hunXieReuse" forIndexPath:indexPath];
        RecommendModel *model = self.hunXieArr[indexPath.row];
        cell.backgroundColor = [UIColor whiteColor];
        [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model.photo_path]];
        cell.priceLabel.text = [NSString stringWithFormat:@"￥%@", [model.price stringValue]];
        cell.recommendLabel.text = [model.like_count stringValue];
        return cell;
    } else if ([collectionView isEqual:self.peiShiCollection]) {
        GoodsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"peiShiReuse" forIndexPath:indexPath];
        RecommendModel *model = self.peiShiArr[indexPath.row];
        cell.backgroundColor = [UIColor whiteColor];
        [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model.photo_path]];
        cell.priceLabel.text = [NSString stringWithFormat:@"￥%@", [model.price stringValue]];
        cell.recommendLabel.text = [model.like_count stringValue];
        return cell;
    } else if ([collectionView isEqual:self.shouShiCollection]) {
        GoodsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"shouShiReuse" forIndexPath:indexPath];
        RecommendModel *model = self.shouShiArr[indexPath.row];
        cell.backgroundColor = [UIColor whiteColor];
        [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model.photo_path]];
        cell.priceLabel.text = [NSString stringWithFormat:@"￥%@", [model.price stringValue]];
        cell.recommendLabel.text = [model.like_count stringValue];
        return cell;
    } else if ([collectionView isEqual:self.hunQingCollection]) {
        GoodsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hunQingReuse" forIndexPath:indexPath];
        RecommendModel *model = self.hunQingArr[indexPath.row];
        cell.backgroundColor = [UIColor whiteColor];
        [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model.photo_path]];
        cell.priceLabel.text = [NSString stringWithFormat:@"￥%@", [model.price stringValue]];
        cell.recommendLabel.text = [model.like_count stringValue];
        return cell;
    } else {
        GoodsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"jiaJuReuse" forIndexPath:indexPath];
        RecommendModel *model = self.jiaJuArr[indexPath.row];
        cell.backgroundColor = [UIColor whiteColor];
        [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model.photo_path]];
        cell.priceLabel.text = [NSString stringWithFormat:@"￥%@", [model.price stringValue]];
        cell.recommendLabel.text = [model.like_count stringValue];
        return cell;
    }
   
}
// 点击
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.hunShaCollection]) {
        GoodsDetailViewController *goodsVC = [[GoodsDetailViewController alloc] init];
        goodsVC.sendModel = self.dataArr[indexPath.row];
        [self.navigationController pushViewController:goodsVC animated:YES];
        [goodsVC release];
    } else if ([collectionView isEqual:self.liFuCollection]) {
        GoodsDetailViewController *goodsVC = [[GoodsDetailViewController alloc] init];
        goodsVC.sendModel = self.liFuArr[indexPath.row];
        [self.navigationController pushViewController:goodsVC animated:YES];
        [goodsVC release];
    } else if ([collectionView isEqual:self.hunXieCollection]) {
        GoodsDetailViewController *goodsVC = [[GoodsDetailViewController alloc] init];
        goodsVC.sendModel = self.hunXieArr[indexPath.row];
        [self.navigationController pushViewController:goodsVC animated:YES];
        [goodsVC release];
    } else if ([collectionView isEqual:self.peiShiCollection]) {
        GoodsDetailViewController *goodsVC = [[GoodsDetailViewController alloc] init];
        goodsVC.sendModel = self.peiShiArr[indexPath.row];
        [self.navigationController pushViewController:goodsVC animated:YES];
        [goodsVC release];
    } else if ([collectionView isEqual:self.shouShiCollection]) {
        GoodsDetailViewController *goodsVC = [[GoodsDetailViewController alloc] init];
        goodsVC.sendModel = self.shouShiArr[indexPath.row];
        [self.navigationController pushViewController:goodsVC animated:YES];
        [goodsVC release];
    } else if ([collectionView isEqual:self.hunQingCollection]) {
        GoodsDetailViewController *goodsVC = [[GoodsDetailViewController alloc] init];
        goodsVC.sendModel = self.hunQingArr[indexPath.row];
        [self.navigationController pushViewController:goodsVC animated:YES];
        [goodsVC release];
    } else {
        GoodsDetailViewController *goodsVC = [[GoodsDetailViewController alloc] init];
        goodsVC.sendModel = self.jiaJuArr[indexPath.row];
        [self.navigationController pushViewController:goodsVC animated:YES];
        [goodsVC release];
    }
}

// 导航控制器返回按钮点击方法
- (void)leftBack:(UIButton *)button
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

// 解析婚纱数据
- (void)createData
{
    self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.HUD setDimBackground:YES];
    self.HUD.labelText = @"努力加载中...";
    [self.HUD show:YES];
    
    self.dataArr = [[NSMutableArray alloc] init];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/products.json?page=1&user_id=984695&category=1&sort=0" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.dataArr addObject:model];
            [model release];
        }
        [self.HUD hide:YES];
        [self.hunShaCollection reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// scroller结束拖拽时触发, 只有不动了才会触发
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    // 判断segment当前是谁
    if (self.backScrollView.contentOffset.x < WIDTH) {
        self.listSegmented.selectedSegmentIndex = 0;
    } else if (self.backScrollView.contentOffset.x < WIDTH * 2) {
        self.listSegmented.selectedSegmentIndex = 1;
    } else if (self.backScrollView.contentOffset.x < WIDTH * 3) {
        self.listSegmented.selectedSegmentIndex = 2;
    } else if (self.backScrollView.contentOffset.x < WIDTH * 4) {
        self.listSegmented.selectedSegmentIndex = 3;
    } else if (self.backScrollView.contentOffset.x < WIDTH * 5) {
        self.listSegmented.selectedSegmentIndex = 4;
    } else if (self.backScrollView.contentOffset.x < WIDTH * 6) {
        self.listSegmented.selectedSegmentIndex = 5;
    } else {
        self.listSegmented.selectedSegmentIndex = 6;	
    }
}

// 解析礼服数据
- (void)createLiFu
{
    self.liFuArr = [[NSMutableArray alloc] init];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/products.json?page=1&user_id=984695&category=2" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.liFuArr addObject:model];
            [model release];
        }
        [self.liFuCollection reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];

}

// 解析婚鞋数据
- (void)createHunXie
{
    self.hunXieArr = [[NSMutableArray alloc] init];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/products.json?page=1&user_id=984695&category=3" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.hunXieArr addObject:model];
            [model release];
        }
        [self.hunXieCollection reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// 解析配饰数据
- (void)createPeiShi
{
    self.peiShiArr = [[NSMutableArray alloc] init];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/products.json?page=1&user_id=984695&category=4" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.peiShiArr addObject:model];
            [model release];
        }
        [self.peiShiCollection reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];

}

// 解析首饰数据
- (void)createShouShi
{
    self.shouShiArr = [[NSMutableArray alloc] init];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/products.json?page=1&user_id=984695&category=5" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.shouShiArr addObject:model];
            [model release];
        }
        [self.shouShiCollection reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];

}

// 解析婚庆用品数据
- (void)createHunQing
{
    self.hunQingArr = [[NSMutableArray alloc] init];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/products.json?page=1&user_id=984695&category=6" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.hunQingArr addObject:model];
            [model release];
        }
        [self.hunQingCollection reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

// 解析家居用品
- (void)createJiaJu
{
    self.jiaJuArr = [[NSMutableArray alloc] init];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/products.json?page=1&user_id=984695&category=7" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *productsArr = dic[@"products"];
        for (NSDictionary *tempDic in productsArr) {
            RecommendModel *model = [[RecommendModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.jiaJuArr addObject:model];
            [model release];
        }
        [self.jiaJuCollection reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];

}

- (void)valueChanged:(id)sender
{
    CCSegmentedControl* segmentedControl = sender;
    switch (segmentedControl.selectedSegmentIndex) {
        case 0:
        {
            [self.backScrollView setContentOffset:CGPointMake(0, 0)];
        }
            break;
        case 1:
        {
            [self.backScrollView setContentOffset:CGPointMake(WIDTH, 0)];

        }
            break;
        case 2:
        {
            [self.backScrollView setContentOffset:CGPointMake(WIDTH * 2, 0)];

        }
            break;
        case 3:
        {
            [self.backScrollView setContentOffset:CGPointMake(WIDTH * 3, 0)];
        }
            break;
        case 4:
        {
            [self.backScrollView setContentOffset:CGPointMake(WIDTH * 4, 0)];
        }
            break;
        case 5:
        {
            [self.backScrollView setContentOffset:CGPointMake(WIDTH * 5, 0)];
        }
            break;
        case 6:
        {
            [self.backScrollView setContentOffset:CGPointMake(WIDTH * 6, 0)];
        }
            break;
            
        default:
            break;
    }

}

- (UIColor *) colorWithHexString: (NSString *) hexString {
    NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString];
    CGFloat alpha, red, blue, green;
    switch ([colorString length]) {
        case 3: // #RGB
            alpha = 1.0f;
            red   = [self colorComponentFrom: colorString start: 0 length: 1];
            green = [self colorComponentFrom: colorString start: 1 length: 1];
            blue  = [self colorComponentFrom: colorString start: 2 length: 1];
            break;
        case 4: // #ARGB
            alpha = [self colorComponentFrom: colorString start: 0 length: 1];
            red   = [self colorComponentFrom: colorString start: 1 length: 1];
            green = [self colorComponentFrom: colorString start: 2 length: 1];
            blue  = [self colorComponentFrom: colorString start: 3 length: 1];
            break;
        case 6: // #RRGGBB
            alpha = 1.0f;
            red   = [self colorComponentFrom: colorString start: 0 length: 2];
            green = [self colorComponentFrom: colorString start: 2 length: 2];
            blue  = [self colorComponentFrom: colorString start: 4 length: 2];
            break;
        case 8: // #AARRGGBB
            alpha = [self colorComponentFrom: colorString start: 0 length: 2];
            red   = [self colorComponentFrom: colorString start: 2 length: 2];
            green = [self colorComponentFrom: colorString start: 4 length: 2];
            blue  = [self colorComponentFrom: colorString start: 6 length: 2];
            break;
        default:
            [NSException raise:@"Invalid color value" format: @"Color value %@ is invalid.  It should be a hex value of the form #RBG, #ARGB, #RRGGBB, or #AARRGGBB", hexString];
            break;
    }
    return [UIColor colorWithRed: red green: green blue: blue alpha: alpha];
}

- (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start length: (NSUInteger) length {
    NSString *substring = [string substringWithRange: NSMakeRange(start, length)];
    NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @"%@%@", substring, substring];
    unsigned hexComponent;
    [[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent];
    return hexComponent / 255.0;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
